#include <malloc.h>
#include "05_lib.h"
nodep InitStack(void)
{
	nodep p = malloc(sizeof(node));
	p->top = -1;
	p->data = NULL;
	return p;
}
void SetEmpty(nodep p)
{
	free(p->data);
	p->top = -1;
	p->data = NULL;
}
int IsEmpty(nodep p)
{
	if(p->top == -1)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
void StackPush(nodep p,int data)
{
	p->data = realloc(p->data,sizeof(int) * (++p->top + 1));
	p->data[p->top] = data;
}
int StackPop(nodep p)
{
	if(1 == IsEmpty(p))
	{
		return 0;
	}
	int data = ShowTop(p);
	p->data = realloc(p->data,sizeof(int) * p->top--);
	if(p->top == -1)
	{
		p->data = NULL;
	}
	return data;
	
}
int ShowTop(nodep p)
{
	if(1 == IsEmpty(p))
	{
		return 0;
	}
	return p->data[p->top];
}
